﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using com.zhongjh.Library.Database1.Enum;

namespace com.zhongjh.Library.Database1
{
    /// <summary>
    /// 数据库连接串实体类
    /// </summary>
    public static class DbCSEntity
    {
        /// <summary>
        /// Sql连接串
        /// </summary>
        public static string strSql = @"Data Source={DbServerNameOrPath};Initial Catalog= {DbName};UID={DbUser};Password={DbPassword};";//OK
        /// <summary>
        /// MySql连接串
        /// </summary>
        public static string strMySql = @"Data Source={DbServerNameOrPath};Initial Catalog={DbName};UID={DbUser};Password={DbPassword}";//OK
        /// <summary>
        /// Oracle连接串
        /// </summary>
        public static string strOracle = @"Data Source={DbServerNameOrPath};Initial Catalog={DbName};UID={DbUser};Password={DbPassword}";


        /// <summary>
        /// OleDbSql连接串
        /// </summary>
        public static string strOleDbSql = @"Provider=SQLOLEDB;Data Source={DbServerNameOrPath};Initial Catalog=pubs;User Id={DBUser};Password={DbPassword};";
        /// <summary>
        /// OleDbAccess连接串
        /// </summary>
        public static string strOleDbAccess = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={DbServerNameOrPath};User Id={DBUser};Password={DbPassword};";//OK
        /// <summary>
        /// OleDbOracle连接串
        /// </summary>
        public static string strOleDbOracle = @"Provider=msdaora;Data Source= {DbName};User Id={DBUser};Password={DbPassword};";
        /// <summary>
        /// OleDbMySql连接串
        /// </summary>
        public static string strOleDbMySql = @"Provider=MySQLProv;Data Source=mydb;User Id={DBUser};Password={DbPassword};";

        /// <summary>
        /// OdbcSql连接串
        /// </summary>
        public static string strOdbcSql = @"Driver={SQL Server};Server=Aron1;Database1={DbName}; Uid={DBUser};Pwd={DbPassword};";
        /// <summary>
        /// OdbcAccess连接串
        /// </summary>
        public static string strOdbcAccess = @"Driver={Microsoft Access Driver (*.mdb)}; Dbq={DbPath}{DbName};Uid={DBUser};Pwd={DbPassword};";
        /// <summary>
        /// OdbcOracle连接串
        /// </summary>
        public static string strOdbcOracle = @"Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid={DBUser};Pwd={DbPassword};";
        /// <summary>
        /// OdbcMySql连接串
        /// </summary>
        public static string strOdbcMySql = @"Driver={mySQL};Server=mySrvName;Option=16834;Database1=myDatabase1;";
        //Driver={MySQL ODBC 3.51 Driver};Database1=dbname;option=0;port=3306;server=localhost; uid=userid;charset=UTF8

        /// <summary>
        /// 取连接串
        /// </summary>
        /// <param name="p_EDbDrive">数据库驱动</param>
        /// <param name="p_EDbType">数据库类型</param>
        /// <param name="p_connectionString">传入连接串</param>
        /// <returns>返回处理后的连接串</returns>
        public static string GetConnectionString(EDbDrive p_EDbDrive, EDbType p_EDbType, string p_connectionString)
        {
            string result = string.Empty;

            EDbDrive dbDrive = (EDbDrive)p_EDbDrive;
            EDbType dbType = (EDbType)p_EDbType;

            if (p_connectionString == string.Empty)
            {
                switch (dbType)
                {
                    case EDbType.Access:
                        switch (dbDrive)
                        {
                            case EDbDrive.OleDb:
                                result = DbCSEntity.strOleDbAccess;
                                break;
                            default:
                                result = DbCSEntity.strOleDbAccess;
                                break;
                        }
                        break;
                    case EDbType.Sql:
                        switch (dbDrive)
                        {
                            case EDbDrive.Sql:
                                result = DbCSEntity.strSql;
                                break;
                            case EDbDrive.OleDb:
                                result = DbCSEntity.strOleDbSql;
                                break;
                            default:
                                result = DbCSEntity.strSql;
                                break;
                        }
                        break;
                    case EDbType.MySql:
                        switch (dbDrive)
                        {
                            case EDbDrive.MySql:
                                result = DbCSEntity.strMySql;
                                break;
                            case EDbDrive.OleDb:
                                result = DbCSEntity.strOleDbMySql;
                                break;
                            default:
                                result = DbCSEntity.strMySql;
                                break;
                        }
                        break;
                    case EDbType.Oracle:
                        switch (dbDrive)
                        {
                            case EDbDrive.Oracle:
                                result = DbCSEntity.strOracle;
                                break;
                            case EDbDrive.OleDb:
                                result = DbCSEntity.strOleDbOracle;
                                break;
                            default: result = DbCSEntity.strOracle;
                                break;
                        }
                        break;
                }
            }
            else
            {
                result = p_connectionString;
            }

            return result;
        }
    }
}
